﻿var rolestructright = {
    gridDefine: {
        columns: [
        //{ display: '表ID', name: 'table_id', minWidth: 60 },
            {display: lang.table_name, name: 'table_name', minWidth: 280 },
            { display: lang.table_code, name: 'table_code', minWidth: 110 },
        //{ display: '备注', name: 'desctription', minWidth: 80 },
        //    {display: '导出权限', name: 'itemname', minWidth: 70, align: 'center' },
            {display: lang.operation, name: 'table_id2', minWidth: 200, render: LinkOP, align: 'center' }
        ],
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryDictTableRoleList",
        params: function () { return $.getPara('roleid'); }
    },
    init: function () {
        getAuthority();
        jsPageRender(this, true);

    },
    search: function () {
        jsPageSearch(this);
    }
};

var authorityArr = [];
function getAuthority() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryDictItemList2",
        model: function () { return 999; },
        success: function (data) {
            if (data) {
                authorityArr = data;
            }
        }
    });
}
function LinkOP(value, row, index) {
    var str = row.itemname||'';
    return '<span id="op_' + row.table_id + '"><a href="javascript:void(0)" onclick="handlerlevel(\'' + row.table_id + '\',\'' + row.itemvalue + '\');">[' + lang.set + ']</a></span>';
}

function LinkOP(value, row, index) {
    
    var html = [];
    html.push('<span id="op_' + row.table_id + '"><select>');
    html.push('<option value="">' + lang.Please_select + '</option>');
    for (var i = 0; i < authorityArr.length; i++) {
        if (row.itemvalue == authorityArr[i].ITEMVALUE) {
            if (lang.SysLanguage == "en") {
                html.push('<option selected="true" value="' + authorityArr[i].ITEMVALUE + '">' + authorityArr[i].ITEMDESC + '</option>');
            }
            else {
                html.push('<option selected="true" value="' + authorityArr[i].ITEMVALUE + '">' + authorityArr[i].ITEMNAME + '</option>');
            }
        }
        else {
            if (lang.SysLanguage == "en") {
                html.push('<option value="' + authorityArr[i].ITEMVALUE + '">' + authorityArr[i].ITEMDESC + '</option>');
            }
            else {
                html.push('<option value="' + authorityArr[i].ITEMVALUE + '">' + authorityArr[i].ITEMNAME + '</option>');
            }
        }
    }
    html.push('</select>');
    html.push('<input type="button" value='+lang.save+' onclick="saveAuthority(' + row.table_id + ')" ></span>');
    return html.join('');

}

function saveAuthority(tableid) {
    if ($('#op_' + tableid + ' select').val() == "") {
        alert(lang.select_pemission_level);
        return;
    }
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryDictTableRoleSave",
        model: function () {
            var obj = {};
            obj.ROLES_ID = $.getPara('roleid');
            obj.STRUCTTABLEID = tableid;
            obj.AUTHORITY = $('#op_' + tableid+' select').val();
            return $.toJSON(obj);
        },
        success: function (data) {
            if (data) {
                rolestructright.search();
            }
        }
    });
}